﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="followlog.aspx.cs" Inherits="weixin.crm.followlog" %>

<!DOCTYPE html>
<html lang="en" style="overflow: hidden;">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <meta charset="utf-8">
    <title><%=Request["tname"] %></title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <link rel="stylesheet" media="screen" href="css/style.css">
    <link rel="stylesheet" type="text/css" href="css/reset.css">
     <link href="css/layui/css/layui.css" rel="stylesheet" />
    <script src="css/layui/layui.js"></script>
    <script src="css/jquery-2.1.0.min.js"></script>
    <script src="css/float.js"></script>
    <script type="text/javascript">
        var form = null, laytpl = null, layer = null, laydate = null;
        layui.use(['form'], function () {
            form = layui.form;
            $.getJSON("api.ashx?Action=getfollowtype&rnd=" + Math.random(), function (data) {
                $.each(data, function (i, row) {
                    $("#followtype").append('<option value="'+row.id+'">'+row.name+'</option>');
                });
                form.render();
            });
        });

        function back() {
            if ($('#remark').val() == '') {
                window.location.href = 'worklogs.aspx';
            }
            else {
                if (confirm("您有未提交的数据，是否确认返回？")) {
                    window.location.href = 'worklogs.aspx';
                }
            }
        }
    </script>
    <style>
        .item {
            width: 80%;
            margin: 0 auto;
            min-height: 380px;
            max-height: 500px;
            z-index: 9999;
            border-radius: 10px;
            display: block;
            position: absolute;
            left: 10%;
            background-color: #fff;
            padding: 10px;
            box-sizing: border-box;
            top: 8%;
        }
    </style>
</head>
<body id="particles-js" style="overflow: hidden;">
        <form class="layui-form layui-form-pane" action="">
        <div style="padding:50px 30px;">
            <div style="background-color: #fff;padding: 3px;border-radius:3px;">
                <div class="layui-form-item">
                <label class="layui-form-label">跟进方式</label>
                <div class="layui-input-block">
                    <select id="followtype" style="width:100px;height:26px;"></select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">公司名称</label>
                <div class="layui-input-block">
                    <input type="hidden" id="cid" value="" />
                    <input onclick="selcompany();" id="company" name="company" readonly="readonly" class="layui-input" placeholder="选择客户" value="" type="text">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">联系人</label>
                <div class="layui-input-block">
                    <input type="hidden" id="lid" value="" />
                    <input type="hidden" id="sex" value="" />
                    <input type="hidden" id="post" value="" />
                    <input onclick="sellinkman();" id="linkman" name="linkman" readonly="readonly" class="layui-input" placeholder="选择联系人" value="" type="text">
                </div>
            </div>
            <div class="layui-form-item">
                <div style="margin-left: 0;" class="layui-input-block">
                    <textarea id="remark" placeholder="请输入洽谈情况" style="width: 100%; border: solid 1px #ccc; height: 120px; margin-top: 10px; resize: none; border-radius: 10px; padding: 10px; box-sizing: border-box;" maxlength="100" cols="3" row="3"></textarea>
                </div>
            </div>
            <p>
            <div onclick="postdata();" style="width: 100%; margin-top: 25px;" class="login-button btn-sign">提交日志</div>
            <div onclick="back();" style="width: 100%; margin-top: 5px; background-color: #ccc;" class="login-button">返回</div>
            </p>
            </div>
        </div>
    </form>
</body>
</html>
<script>
    var form = null, layer = null, table = null;
    var options = {
        elem: '#mylist', url: "api.ashx?Action=getcustlist&rnd=" + Math.random(), page: true, even: true, limit: 8, limits: [8]
        , cols: [[
            { field: 'name', title: '客户名称', width: '75%' },
            {
                field: '', title: '选择', width: '25%', templet: function (item) {
                    return '<input type="button" onclick="selcust(\'' + item.id + '\',\''+item.name+'\');" class="layui-btn layui-btn-xs" value="选择" />';
                }
            }
        ]]
    };
    var options1 = {
        elem: '#mylist1', url: "api.ashx?Action=getlinkmanlist&cid=0&rnd=" + Math.random(), page: false, even: true, limit: 8, limits: [8]
        , cols: [[
            { field: 'name', title: '姓名', width: '45%', templet: function (item) { return item.name+'('+item.sex+')';} },
            { field: 'post', title: '职位', width: '30%' },
            {
                field: '', title: '选择', width: '25%', templet: function (item) {
                    return '<input type="button" onclick="sellink(\'' + item.id + '\',\'' + item.name + '\',\'' + item.sex + '\',\'' + item.post + '\');" class="layui-btn layui-btn-xs" value="选择" />';
                }
            }
        ]]
    };
    layui.use(['form', 'table'], function () {
        form = layui.form;layer = layui.layer;table = layui.table;
    });
    function selcust(id, name) {
        $("#cid").val(id);
        $("#company").val(name);
        $("#lid").val("");
        $("#linkman").val("");
        layer.closeAll();
    }
    function sellink(id, name,sex,post) {
        $("#lid").val(id);
        $("#linkman").val(name);
        $("#sex").val(sex);
        $("#post").val(post);
        layer.closeAll();
    }
    function selcompany() {
        layer.open({
            type: 1,
            title: 0,
            closeBtn: 0,
            area: ['90%', '90%'],
            btn: ['关闭'],
            content: '<table id="mylist" style="display:block; margin:0 auto;"></table>',
            success: function () {
                list = table.render(options);
            }
        });
    }
    function sellinkman() {
        layer.open({
            type: 1,
            title: 0,
            closeBtn: 0,
            area: ['90%', '200px'],
            btn: ['关闭'],
            content: '<table id="mylist1" style="display:block; margin:0 auto;"></table>',
            success: function () {
                $.extend(options1, { url: "api.ashx?Action=getlinkmanlist&cid="+$("#cid").val()+"&rnd=" + Math.random() });
                list = table.render(options1);
            }
        });
    }
    function postdata() {
        $.ajax({
            url: "api.ashx?rnd=" + Math.random(),
            type: "POST",
            data: { Action: "follow", followtype_val: $("#followtype").find("option:selected").val(), followtype: $("#followtype").find("option:selected").text(), cid: $("#cid").val(), remark: $("#remark").val(), man: $("#linkman").val(), sex: $("#sex").val(), post: $("#post").val() },
            dataType: "json",
            success: function (data) {
                if (data.success == true) {
                    alert('保存日志成功！');
                    window.location.href = "worklogs.aspx";
                }
                else {
                    alert('保存日志失败,' + data.info);
                }
            },
            error: function () {
                alert('保存日志失败！');
            }
        });
    }
</script>